<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="info" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="进货单别" v-if="judgeShow('th001')">
				<u-input v-model="info.th001" placeholder="进货单别" disabled></u-input>
			</u-form-item>
			<u-form-item label="进货单号" v-if="judgeShow('th002')">
				<u-input v-model="info.th002" placeholder="进货单号" disabled></u-input>
			</u-form-item>
			<u-form-item label="进货日期" v-if="judgeShow('th003')">
				<u-input v-model="info.th003" placeholder="进货日期" disabled></u-input>
			</u-form-item>
			<u-form-item label="供应商"   v-if="judgeShow('th005')">
				<u-input v-model="info.th005" placeholder="供应商" disabled></u-input>
			</u-form-item>
		  
			<u-form-item label="供应商单号"   v-if="judgeShow('th006')">
				<u-input v-model="info.th006" placeholder="供应商单号" disabled></u-input>
			</u-form-item>
			
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in moctiList" :key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="品号" v-if="judgeShow('moctiList-ti004')">
						<u-input v-model="item.ti004" placeholder="品号" disabled></u-input>
					</u-form-item>
					<u-form-item label="品名" v-if="judgeShow('moctiList-ti005')">
						<u-input v-model="item.ti005" placeholder="品名" disabled></u-input>
					</u-form-item>
					<u-form-item label="规格" v-if="judgeShow('moctiList-ti006')">
						<u-input v-model="item.ti006" placeholder="规格" disabled></u-input>
					</u-form-item>
					<u-form-item label="进货数量" v-if="judgeShow('moctiList-ti007')">
						<u-input v-model="item.ti007" placeholder="进货数量" disabled></u-input>
					</u-form-item>
					<u-form-item label="单位" v-if="judgeShow('moctiList-ti008')">
						<u-input v-model="item.ti008" placeholder="单位" disabled></u-input>
					</u-form-item>
			
					<u-form-item label="仓库" v-if="judgeShow('moctiList-ti009')">
						<u-input v-model="item.ti009" placeholder="最终单价" disabled></u-input>
					</u-form-item>
					<u-form-item label="仓库名称" v-if="judgeShow('moctiList-ti0015')">
						<u-input v-model="item.ti0015" placeholder="仓库名称" disabled></u-input>
					</u-form-item>
					<u-form-item label="验收数量" v-if="judgeShow('moctiList-ti019')">
						<u-input v-model="item.ti019" placeholder="验收数量" disabled></u-input>
					</u-form-item>
					 <u-form-item label="验退数量" v-if="judgeShow('moctiList-ti019')">
					 	<u-input v-model="item.ti019" placeholder="验退数量" disabled></u-input>
					 </u-form-item>
					<u-form-item label="工单单别" v-if="judgeShow('moctiList-ti013')">
						<u-input v-model="item.ti013" placeholder="工单单别" disabled></u-input>
					</u-form-item>
				   <u-form-item label="工单单号" v-if="judgeShow('moctiList-ti014')">
				   	<u-input v-model="item.ti014" placeholder="工单单别" disabled></u-input>
				   </u-form-item>
				   <u-form-item label="批号" v-if="judgeShow('moctiList-ti010')">
				   	<u-input v-model="item.ti010" placeholder="工单单别" disabled></u-input>
				   </u-form-item>
					 <u-form-item label="备注" v-if="judgeShow('moctiList-ti040')">
					 	<u-input v-model="item.ti040" placeholder="" disabled></u-input>
					 </u-form-item>
					 
				</view>
			</view>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<u-form-item label="检测结果" v-if="judgeShow('udf13')" >
					<!-- 1允许 2拒收 3其他 -->
					 <u-radio-group
					    v-model="resultName"
					    placement="row"
					  >
					    <u-radio
					      :customStyle="{marginBottom: '8px'}"
					      v-for="(radioItem, radioIndex) in resultRadio"
					      :key="radioIndex"
						 :disabled='true'
					      :name="radioItem.name"
					    >
						 {{radioItem.name}}
					    </u-radio>
					  </u-radio-group>
				</u-form-item>
				<u-form-item label="依据" v-if="judgeShow('udf20')">
					<u-input v-model="info.udf20" placeholder="依据" disabled></u-input>
				</u-form-item>
				<u-form-item label="抽样数" v-if="judgeShow('udf21')"  >
					<u-input v-model="info.udf21" placeholder="抽样数" disabled></u-input>
				</u-form-item>
				<u-form-item label="严重缺陷" v-if="judgeShow('udf22')"  >
					<u-input v-model="info.udf22" placeholder="严重缺陷" disabled></u-input>
				</u-form-item>
				<u-form-item label="主要缺陷" v-if="judgeShow('udf23')"  >
					<u-input v-model="info.udf23" placeholder="主要缺陷" disabled></u-input>
				</u-form-item>
				<u-form-item label="次要缺陷" v-if="judgeShow('udf24')"  >
					<u-input v-model="info.udf24" placeholder="次要缺陷" disabled></u-input>
				</u-form-item>
			</view>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in moctiaList" :key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="检测项目" v-if="judgeShow('moctiaList-ti004')">
						<u-input v-model="item.ti004" placeholder="检测项目" disabled></u-input>
					</u-form-item>
					<u-form-item label="检验标准说明"  labelWidth='200' v-if="judgeShow('moctiaList-ti006')">
						<u-input v-model="item.ti006" placeholder="检验标准说明" disabled></u-input>
					</u-form-item>
					<u-form-item label="判定" v-if="judgeShow('moctiaList-ti007')">
						<u-input v-model="item.ti007" placeholder="判定" disabled></u-input>
					</u-form-item>
					<u-form-item label="备注" v-if="judgeShow('moctiaList-ti008')">
						<u-input v-model="item.ti008" placeholder="备注" disabled></u-input>
					</u-form-item>
					<u-form-item label="附件" v-if="judgeShow('moctiaList-ti009')">
						<jnpf-file v-model="item.ti009" disabled />
					</u-form-item>
				</view>
			</view>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<u-form-item label="公司XRF检测" labelWidth='200' v-if="judgeShow('udf29')" >
					<u-input v-model="info.udf29" placeholder="报告编号" disabled></u-input>
				</u-form-item>
				<u-form-item label="报告编号" v-if="judgeShow('udf29')"  >
					<u-input v-model="info.udf29" placeholder="报告编号" disabled></u-input>
				</u-form-item>
			</view>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<u-form-item label="会签部门人员" v-if="judgeShow('udf14')" labelWidth='200'>
					{{udf14Name(info.udf14)}}
				</u-form-item>
				<u-form-item label="标准" v-if="judgeShow('udf23')">
					<u-input v-model="info.udf23" placeholder="标准" disabled></u-input>
				</u-form-item>
				<u-form-item label="标准时间" v-if="judgeShow('udf24')">
					<u-input v-model="info.udf24" placeholder="标准时间" disabled></u-input>
				</u-form-item>
				<u-form-item label="审核" v-if="judgeShow('udf25')">
					<u-input v-model="info.udf25" placeholder="审核" disabled></u-input>
				</u-form-item>
				<u-form-item label="审核时间" v-if="judgeShow('udf26')">
					<u-input v-model="info.udf26" placeholder="审核时间" disabled></u-input>
				</u-form-item>
				<u-form-item label="填表" v-if="judgeShow('udf27')">
					<u-input v-model="info.udf27" placeholder="填表" disabled></u-input>
				</u-form-item>
				<u-form-item label="填表时间" v-if="judgeShow('udf28')">
					<u-input v-model="info.udf28" placeholder="填表时间" disabled></u-input>
				</u-form-item>
			</view>
			
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<u-form-item label="检测结果" v-if="judgeShow('udf16')" >
					<!-- 1允许 2拒收 3其他 -->
					 <u-radio-group
					    v-model="resultEndName"
					    placement="row"
					  >
					    <u-radio
					      :customStyle="{marginBottom: '8px'}"
					      v-for="(radioItem, radioIndex) in resultEndRadio"
					      :key="radioIndex"
						 :disabled='true'
					      :name="radioItem.name"
					    >
						 {{radioItem.name}}
					    </u-radio>
					  </u-radio-group>
				</u-form-item>
			 
			</view>
		</u-form>
	</view>
</template>

<script>
	import {
		getMocth
	} from '@/api/workFlow/flowEngine'
	import {
		getDataInterfaceDataInfo,
		getDictionaryDataSelector,
		getDataInterfaceRes
	} from '@/api/common'
	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update
	} from '@/api/apply/order'
	export default {
		name: 'crmOrder',
		mixins: [comMixin],
		data() {
			return {
				hide: false,
				billEnCode: 'OrderNumber',
				dataForm: {

				},
				resultName:'',
				resultRadio:[
					{
						name:'允许',
						id:1,
						 disabled: true,
					},
					{
						name:'拒收',
						id:2,
						disabled: true,
					},
					{
						name:'其他',
						id:3,
						disabled: true,
					},
				],
				resultEndName:'',
				resultEndRadio:[
					{
						name:'拒收',
						id:1,
						 disabled: true,
					},
					{
						name:'特采',
						id:2,
						disabled: true,
					},
					{
						name:'挑选',
						id:3,
						disabled: true,
					},
				],
				lst: [],
				formConf: {},
				id: '',
				buyName: '',
				buyTwoName: '',
				shuizhoLst: [],
				info: {},//基本信息
				moctiList:[],//进货信息
				moctiaList:[],//检测信息列表
				udf14Lst:[],//会签部门字段
			}
		},
		computed: {
			tb010CName(enCode) {
				return enCode => {
					let txt = ''
					let arr = this.shuizhoLst.forEach(item => {
						if (item.enCode == enCode) {
							console.log('item', item)
							txt = item.fullName
						}
					})
					return txt
				}
			},
			udf14Name(udf14Arr){
				 return udf14Arr=>{
					 let arr=[]
					 this.udf14Lst.forEach(item=>{
						 udf14Arr.forEach(childrenItem=>{
							 if(item.F_Id==childrenItem){
								 arr.push(item.F_RealName)
							 }
						 })
					 })
					return  arr.join(',')
				 }
			},
			 
		},
		methods: {

			init(data, id, flowFormContentJson) {
				this.setting = data
				this.id = id
				this.getInfo(data)

			},
			getInfo(data) {
				getMocth(data.id).then(res => {
					 
					if (res.code == 200) {
						this.info = res.data
						this.getDataInterfaceDataInfoMV002(this.info.th005)
						this.moctiList = res.data.moctiList
						this.moctiaList = res.data.moctiaList
						this.moctiList.forEach(item=>{
							let data = {
								id:item.ti009,
								interfaceId: '362114335423601221',
								propsValue: 'MC001',
								relationField: 'MC001',
							}
							getDataInterfaceDataInfo('362114335423601221', data).then(res => {
								if (res.code == 200) 
								{
									  item.ti0015= res.data.MC002
								}
							})
						})
						console.log('this.moctiaList',this.moctiaList.length)
						if(	this.info.udf13==1){
							this.resultName='允许'
						}
						if(	this.info.udf13==2){
							this.resultName='拒收'
						}
						 if(	this.info.udf13==3){
						 	this.resultName='其他'
						 }
						if(this.info.udf19==1){
							this.resultEndName='拒收'
						}
						if(this.info.udf19==2){
							this.resultEndName='特采'
						}
						if(this.info.udf19==3){
							this.resultEndName='挑选'
						}
						this.moctiaList.forEach(item=>{
							if(item.ti007=='Y'){
								item.ti007='合格'
							}else{
								item.ti007='不合格'
							}
							getDataInterfaceDataInfo('487505809102674245',{
								id:item.ti004,
								interfaceId: '487505809102674245',
								propsValue: 'ME001',
								relationField: 'ME002',
							}).then(res=>{
								if(res.code==200){
									item.ti004=res.data.ME002
								}
							})
						})
						
						this.getDataInterfaceDataInfoPeople()
						 
						this.getDictionaryDataSelectorByTb020()
					}
				})
			},
			getDataInterfaceDataInfoPeople(){
				getDataInterfaceRes('482455778746334405').then(res=>{
					if(res.code==200){
						this.udf14Lst=res.data.data //会签部门数据
					}
				})
			},
			getDictionaryDataSelectorByTb020() {
				getDictionaryDataSelector('411695330707391429').then(res => {
					console.log('res===getDictionaryDataSelector==', res)
					if (res.code == 200) {
						this.shuizhoLst = res.data.list
					}
				})
			},
			getDataInterfaceDataInfoMV002(id) {
				let data = {
					id,
					interfaceId: '381247065990113925',
					propsValue: 'MA001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('381247065990113925', data).then(res => {
						console.log('res====getDataInterfaceDataInfoMV002=======',res)
					if (res.code == 200) {
						this.info.th005 = res.data.JoinStr
					}
				})
			},
			getDataInterfaceDataInfoMV003(id) {
				let data = {
					id,
					interfaceId: '381240499823979141',
					dblink: this.id,
					propsValue: 'ME001',
					relationField: 'ME002',
				}
				getDataInterfaceDataInfo('381240499823979141', data).then(res => {
					if (res.code == 200) {
						this.buyTwoName = res.data.ME002

					}
				})
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},
			initData() {
				getGoodsList().then(res => {
					this.goodsOptions = res.data.list
				})
				getCustomerList().then(res => {
					this.customerOptions = res.data.list
				})
			},
			selfInit() {
				this.addGoods()
				this.addPlan()
			},
			onChange(e) {
				const user = e[0]
				this.dataForm.salesmanName = user.fullName
			},
			addGoods() {
				const item = {
					goodsId: '',
					goodsCode: '',
					goodsName: '',
					specifications: '',
					unit: '',
					qty: '',
					price: '',
					amount: '',
					discount: null,
					cess: null,
					actualPrice: '',
					actualAmount: '',
					description: ''
				}
				this.dataForm.goodsList.push(item)
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1)
			},
			addPlan() {
				const item = {
					receivableDate: '',
					receivableRate: '',
					receivableMoney: '',
					receivableMode: '',
					abstract: ''
				}
				this.dataForm.collectionPlanList.push(item)
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1)
			},
			onGoodsChange(e, i) {
				const goods = e[0]
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: ''
				}
				this.$forceUpdate()
			},
			onCustomerChange(e) {
				const customer = e[0]
				this.dataForm.customerName = customer.text
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(parseFloat(row.price) * parseFloat(row.qty))
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(discountPrice * (1 + (row.cess / 100)));
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(parseFloat(row.actualPrice) * parseFloat(row
					.qty))
				this.$forceUpdate()
			}
		}
	}
</script>